package com.zmzncs.lmtc.module.order.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zmzncs.lmtc.common.pojo.PageInfo;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.*;
import com.zmzncs.lmtc.module.customer.dao.CardRecordDao;
import com.zmzncs.lmtc.module.customer.service.CustInfoService;
import com.zmzncs.lmtc.module.order.dao.OrderInfoDao;
import com.zmzncs.lmtc.module.order.pojo.order_refund.OrderRefundAuditForm;
import com.zmzncs.lmtc.module.order.pojo.order_refund.OrderRefundDTO;
import com.zmzncs.lmtc.module.order.pojo.order_refund.OrderRefundTableVO;
import com.zmzncs.lmtc.module.order.service.OrderRefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 订单-退款 前端控制器
 * </p>
 *
 * @author 任建波
 * @since 2020-10-21
 */
@Api(tags = "退款")
@RestController
@RequestMapping("/order/order-refund")
@Validated
@Slf4j
public class OrderRefundController {

    @Autowired
    OrderRefundService orderRefundService;
    @Autowired
    HttpServletRequest request;
    @Autowired
    CardRecordDao cardRecordDao;
    @Autowired
    OrderInfoDao orderInfoDao;
    @Autowired
    CustInfoService custInfoService;


    @ApiOperation(value = "获取退款列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name="pageNum", value="页码", required = true),
            @ApiImplicitParam(paramType="query", name="pageSize", value="页长", required = true),
            @ApiImplicitParam(paramType="query", name="keyword", value="关键字"),
    })
    @GetMapping(value = "get-refund-list")
    public Rest<PageInfo<OrderRefundTableVO>> getRefundList(@NotNull Integer pageNum, @NotNull Integer pageSize, String keyword) {
        IPage<OrderRefundDTO> refundList = orderRefundService.getRefundList(new Page(pageNum, pageSize));
        PageInfo<OrderRefundTableVO> pageInfo = JsonUtil.pageTransform(refundList, OrderRefundTableVO.class);

        return RestUtil.success(pageInfo);
    }

    @ApiOperation(value = "进出场缴费审核退款")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping(value = "audit-refund")
    public Rest auditRefund(@Valid OrderRefundAuditForm form) {
        /**
         * 1、客户购买了月租卡，如果客户出场异常，使用了现金支付，
        *     则客户可以申请退款，退款金额在购买月租卡的微信支付订单中退款
         * */

        orderRefundService.auditRefund(form);

        return RestUtil.success();
    }


    @ApiOperation(value = "预约费用审核退款")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping(value = "reserve-refund")
    public Rest reserveRefund(@Valid String orderCode) {
        String refund = orderRefundService.reserveRefund(orderCode);

        return RestUtil.success(refund);
    }


}